package org.example.alicloud.controller;

import org.example.alicloud.model.CommonResult;
import org.example.alicloud.model.Payment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * @author gaoqiang
 */
@RestController
public class PaymentController {

    @Value("${server.port}")
    private String serverPort;

    private static HashMap<Long, Payment> hashMap = new HashMap<Long, Payment>();
    static {
        hashMap.put(1L, new Payment(1L, "21281"));
        hashMap.put(2L, new Payment(2L, "21282"));
        hashMap.put(3L, new Payment(3L, "21283"));
    }

    @GetMapping("/payment/hash/{id}")
    public CommonResult<Payment> getPaymentFromHashMap(@PathVariable("id") Long id){
        Payment payment = hashMap.get(id);
        CommonResult<Payment> result = new CommonResult<>(200, "nacos registry, from hash map, server port:"+serverPort+"\t id:"+id, payment);
        return result;
    }

    @GetMapping("/payment/nacos/{id}")
    public String getPayment(@PathVariable("id") Integer id){
        return "nacos registry, from hash map, server port:"+serverPort+"\t id:"+id;
    }
}
